[feat/MAT-358] undo/redo command 패턴 HistoryManager#300
Open
b0nsu wants to merge 1 commit intorefactor/mat-355-renderingfrom
Open
[feat/MAT-358] undo/redo command 패턴 HistoryManager#300b0nsu wants to merge 1 commit intorefactor/mat-355-renderingfrom
b0nsu wants to merge 1 commit intorefactor/mat-355-renderingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces the existing array-based undo/redo history in pointer-native-drawing with a command-pattern HistoryManager, using lightweight document snapshots to enable fast state restoration and prepare for future eraser optimizations (bounds/cached paths).
Changes:
- Added
HistoryManagerwith command entries for append-stroke / erase-strokes / replace-document. - Updated
DrawingCanvasto push/undo/redo viaHistoryManagerinstead of deep-copied history arrays. - Introduced new drawing model types (
DrawingCanvasProps,DocumentSnapshot, etc.) to support snapshot/history workflows.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/pointer-native-drawing/src/model/drawingTypes.ts | Adds new public-facing(?) types for canvas props and snapshot/history modeling. |
| packages/pointer-native-drawing/src/engine/HistoryManager.ts | Implements the command-pattern history stack with undo/redo, eviction hooks, and erase transactions. |
| packages/pointer-native-drawing/src/DrawingCanvas.tsx | Rewires stroke/text editing + undo/redo to use HistoryManager and snapshot application. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
26
to
33
| import { | ||
| type DrawingCanvasProps, | ||
| type DrawingCanvasRef, | ||
| type DocumentSnapshot, | ||
| type Point, | ||
| type Stroke, | ||
| type TextItem, | ||
| type DrawingCanvasRef, | ||
| } from './model/drawingTypes'; |
| type DrawingCanvasRef, | ||
| } from './model/drawingTypes'; | ||
| import { deepCopyStrokes, deepCopyTexts, safeMax } from './model/strokeUtils'; | ||
| import { deepCopyTexts, safeMax, computeStrokeBounds } from './model/strokeUtils'; |
Comment on lines
+115
to
+119
| /** 현재 stroke 상태의 경량 스냅샷 (reference 저장, deep copy 아님) */ | ||
| const createSnapshot = useCallback((): DocumentSnapshot => ({ | ||
| strokes: strokesRef.current, | ||
| bounds: strokesRef.current.map((s) => computeStrokeBounds(s.points)), | ||
| }), []); |
Comment on lines
+54
to
+70
| export type DrawingCanvasProps = { | ||
| strokeColor?: string; | ||
| strokeWidth?: number; | ||
| onChange?: (strokes: Stroke[]) => void; | ||
| onHistoryChange?: (canUndo: boolean, canRedo: boolean) => void; | ||
| eraserMode?: boolean; | ||
| eraserSize?: number; | ||
| textMode?: boolean; | ||
| textFontPath?: number; | ||
| }; | ||
|
|
||
| // ── Snapshot (lightweight — stores references, not deep copies) ─ | ||
|
|
||
| export type DocumentSnapshot = { | ||
| readonly strokes: readonly Stroke[]; | ||
| readonly bounds: readonly StrokeBounds[]; | ||
| }; |
9289a05 to
41f727a
Compare
…ncremental + lazy init - engine/HistoryManager.ts: command 패턴 (AppendStroke / EraseStrokes) - append-stroke undo: O(1) — slice로 마지막 stroke 제거 - erase-strokes: snapshot 복원 (begin/commit/discardTransaction) - model/drawingTypes.ts: DocumentSnapshot, DrawingCanvasProps 추가 - DrawingCanvas.tsx: - HistoryManager 통합 (legacy historyRef/saveToHistory/restoreFromHistory 제거) - strokeBoundsRef incremental 관리 — createSnapshot 매 호출 N×P 재계산 회피 (Critical fix) - HistoryManager lazy init — useRef(null) + nullish-coalescing assign Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
521676e to
d27224b
Compare
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
배열 기반 히스토리를 command pattern HistoryManager로 교체합니다.
DocumentSnapshot + StrokeBounds로 undo 시 O(1) 복원, 이후 eraser 최적화 기반을 마련합니다.
Linear
Changes
engine/HistoryManager.ts생성 — command pattern (AppendStroke, EraseStrokes, ReplaceDocument)Testing
pnpm typecheck통과pnpm lint통과Risk / Impact